home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / SHADOW_D.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  10.3 KB  |  345 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.output.drawable;
  5. import sub_arctic.output.shadow_drawable;
  6. import sub_arctic.input.event;
  7. import java.awt.Dimension;
  8. import java.awt.Point;
  9.  
  10. /** 
  11.  * Specialized subclass of drag_container that casts a shadow under the 
  12.  * objects it drags while they are being dragged.   This is done by drawing
  13.  * the child objects twice (when they are being dragged), once as a shadow
  14.  * using a shadow_drawable drawable object, and then again normally on top of
  15.  * that.
  16.  *  
  17.  *  @see sub_arctic.lib.drag_container
  18.  *  @see sub_arctic.lib.shadow_caster
  19.  *  @see sub_arctic.output.shadow_drawable
  20.  *
  21.  *  @author Scott Hudson
  22.  */
  23. public class shadow_drag_container extends drag_container {
  24.  
  25.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  26.  
  27.    /** 
  28.     * Do we do expensive but realistic drawing of shadows for images, or do 
  29.     * we just do their bounding rectangle?  Default is to be cheap about it.
  30.     */
  31.    protected boolean _expensive_draw = false;
  32.  
  33.    /** 
  34.     * Are currently doing expensive but realistic drawing shadows for images, 
  35.     * or do are we just drawing their bounding rectangle?
  36.     * @return boolean indicating if we are drawing in expensive mode.
  37.     */
  38.    public boolean expensive_draw() {return _expensive_draw;} 
  39.  
  40.    /** Set whether we draw image shadows realistically, but expensively (slow),
  41.     *  or just draw their bounding rectangles (fast).
  42.     *
  43.     *  @param v true if we draw slow but realistic images, false if we draw fast
  44.     */
  45.    public void set_expensive_draw(boolean v) 
  46.      {
  47.        if (v != _expensive_draw)
  48.      {
  49.            _expensive_draw = v;
  50.        damage_self(); 
  51.      }
  52.      }
  53.  
  54.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  55.  
  56.   /** Full constructor. 
  57.    *
  58.    * @param x             x position of the container within its parent's coords
  59.    * @param y             y position of the container within its parent's coords
  60.    * @param shad_x_offset offset of shadow in x direction
  61.    * @param shad_y_offset offset of shadow in y direction
  62.    */
  63.   public shadow_drag_container(int x, int y, int shad_x_off, int shad_y_off) 
  64. {
  65.       super(x,y,false);
  66.       _x_offset = 0; _y_offset = 0;
  67.       set_offset(shad_x_off, shad_y_off);
  68.     }
  69.  
  70.    //had:
  71.    //* @exception general PROPAGATED
  72.  
  73.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  74.  
  75.   /** 
  76.    * Constructor with default shadow offsets.
  77.    *
  78.    * @param x x position of the container within its parent's coords
  79.    * @param y y position of the container within its parent's coords
  80.    */
  81.   public shadow_drag_container(int x, int y) 
  82. {
  83.       this(x,y, shadow_drawable.default_off_x, shadow_drawable.default_off_y);
  84.     }
  85.  
  86.    //had:
  87.    //* @exception general PROPAGATED
  88.  
  89.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  90.  
  91.    /** X offset for shadow */
  92.    protected int _x_offset;
  93.  
  94.    /** 
  95.     * X offset for shadow.
  96.     * @return int the x offset for the shadow.
  97.     */
  98.    public int x_offset() {return _x_offset;}
  99.  
  100.    /** 
  101.     * Set x offset for shadow.
  102.     * @param xoff the new x offset
  103.     */
  104.    public void set_x_offset(int xoff) 
  105. {
  106.        /* need a redraw after this */
  107.        damage_self();
  108.  
  109.        _x_offset = xoff;
  110.  
  111.        /* set shrink_wrap border to be 2 larger than the shadow */
  112.        set_border(Math.max(_x_offset,_y_offset)+2);
  113.      }
  114.  
  115.     //had:
  116.     //* @exception general PROPAGATED
  117.  
  118.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  119.  
  120.    /** Y offset for shadow */
  121.    protected int _y_offset;
  122.  
  123.    /** 
  124.     * Y offset for shadow. 
  125.     * @return int the y offset for the shadow.
  126.     */
  127.    public int y_offset() {return _y_offset;}
  128.  
  129.    /** 
  130.     * Set y offset for shadow.
  131.     * @param yoff the new y offset
  132.     */
  133.    public void set_y_offset(int yoff) 
  134. {
  135.        /* need a redraw after this */
  136.        damage_self();
  137.  
  138.        _y_offset = yoff;
  139.  
  140.        /* set shrink_wrap border to be 2 larger than the shadow */
  141.        set_border(Math.max(_x_offset,_y_offset)+2);
  142.      }
  143.  
  144.     //had:
  145.     //* @exception general PROPAGATED
  146.  
  147.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  148.  
  149.    /** Set offset for shadow 
  150.     *
  151.     * @param xoff the new x offset
  152.     * @param yoff the new y offset
  153.     */
  154.    public void set_offset(int xoff, int yoff) 
  155. {
  156.        /* need a redraw after this */
  157.        damage_self();
  158.  
  159.        _x_offset = xoff;
  160.        _y_offset = yoff;
  161.  
  162.        /* set shrink_wrap border to be 2 larger than the shadow */
  163.        set_border(Math.max(_x_offset,_y_offset)+2);
  164.      }
  165.  
  166.     //had:
  167.     //* @exception general PROPAGATED
  168.  
  169.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  170.  
  171.    /** 
  172.     * Handle the start of a drag to the object.  
  173.     *
  174.     * @param evt the event starting the drag
  175.     * @param x_pos     x position of the drag (in parent's coordinates)
  176.     * @param y_pos     y position of the drag (in parent's coordinates)
  177.     * @param grab_x    x position where object was grabbed (in local coords)
  178.     * @param grab_y    y position where object was grabbed (in local coords)
  179.     * @param user_info info object (originally passed to the focus agent)
  180.     * @return whether the input was consumed/accepted
  181.     */
  182.    public boolean drag_start(
  183.      event evt, 
  184.      int x_pos, int y_pos, 
  185.      int grab_x, int grab_y, 
  186.      Object user_info)
  187.      {
  188.        boolean result;
  189.  
  190.        /* let super class do the work */
  191.        result = super.drag_start(evt, x_pos, y_pos, grab_x, grab_y, user_info);
  192.  
  193.        /* move the object over to simulate a lift off of the surface */
  194.        set_pos(x_pos-x_offset(), y_pos-y_offset());
  195.  
  196.        return result;
  197.      }
  198.  
  199.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  200.  
  201.    /** 
  202.     * Handle a movement during a drag.  Here we set our position (offset by
  203.     * the shadow size) to follow the drag location. 
  204.     *
  205.     * @param evt the event starting the drag
  206.     * @param x_pos     x position of the drag (in parent's coordinates)
  207.     * @param y_pos     y position of the drag (in parent's coordinates)
  208.     * @param st_x      starting x position of the drag (in parent's coords)
  209.     * @param st_y      starting y position of the drag (in parent's coords)
  210.     * @param grab_x    x position where object was grabbed (in local coords)
  211.     * @param grab_y    y position where object was grabbed (in local coords)
  212.     * @param user_info info object (originally passed to the focus agent)
  213.     * @return whether the input was consumed/accepted
  214.     */
  215.   public boolean drag_feedback(
  216.     event evt, 
  217.     int x_pos, int y_pos, 
  218.     int st_x, int st_y, 
  219.     int grab_x, int grab_y, 
  220.     Object user_info)
  221.     {
  222.       /* move our position */
  223.       set_pos(x_pos - x_offset(), y_pos - y_offset());
  224.       return true;
  225.     }
  226.  
  227.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  228.  
  229.    /** 
  230.     * Handle input corresponding to the end of a drag.  
  231.     * @param evt the event starting the drag
  232.     * @param x_pos     x position of the drag (in parent's coordinates)
  233.     * @param y_pos     y position of the drag (in parent's coordinates)
  234.     * @param st_x      starting x position of the drag (in parent's coords)
  235.     * @param st_y      starting y position of the drag (in parent's coords)
  236.     * @param grab_x    x position where object was grabbed (in local coords)
  237.     * @param grab_y    y position where object was grabbed (in local coords)
  238.     * @param user_info info object (originally passed to the focus agent)
  239.     * @return whether the input was consumed/accepted
  240.     */
  241.    public boolean drag_end(
  242.     event evt,
  243.     int x_pos, int y_pos,
  244.     int start_x, int start_y,
  245.     int grab_x, int grab_y,
  246.     Object user_info)
  247.     {
  248.       boolean result;
  249.  
  250.       /* let super class do the work */
  251.       result = super.drag_end(
  252.     evt, x_pos, y_pos, start_x, start_y, grab_x, grab_y, user_info);
  253.  
  254.       /* move back to normal to simulate touch down */
  255.       set_pos(x_pos, y_pos);
  256.  
  257.       return result;
  258.     }
  259.  
  260.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  261.  
  262.    /** 
  263.     * Draw self.  If we are not being dragged, we just draw our children.
  264.     * If we are, we draw our children twice, once in shadow offset by
  265.     * a small translation, then again in normal colors.
  266.     *
  267.     * @param d the drawable object we are to draw on.
  268.     */
  269.    protected void draw_self_local(drawable d) 
  270. {
  271.        if (flag_is_set(DOING_DRAG))
  272.      {
  273.            shadow_drawable shadow_d;
  274.            shadow_d = new shadow_drawable(d,x_offset(),y_offset());
  275.        shadow_d.set_expensive_draw(expensive_draw());
  276.  
  277.            draw_children(shadow_d);
  278.            draw_children(d);
  279.      }
  280.        else
  281.      {
  282.        draw_children(d);
  283.      }
  284.      }
  285.  
  286.     //had:
  287.     //* @exception general PROPAGATED
  288.  
  289.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  290.  
  291.    /** 
  292.     * Catch damage from our children and make it bigger to account for the
  293.     * shadow.
  294.     *
  295.     * @param top_left top-left corner of damage area (in our coords)
  296.     * @param sz       size of damage area
  297.     */
  298.    public void damage_from_child(Point top_left, Dimension sz) 
  299. {
  300.     int       px, py;
  301.     Point     new_pt;
  302.         Dimension larger_sz;
  303.  
  304.         /* expand the size to include extra for the shadow */
  305.         larger_sz = new Dimension(sz.width + Math.abs(_x_offset), 
  306.                               sz.height+ Math.abs(_y_offset));  
  307.  
  308.     /* if this was negative, move top & left edges */
  309.     if (_x_offset < 0) 
  310.       px = top_left.x + _x_offset;
  311.     else
  312.       px = top_left.x;
  313.     if (_y_offset < 0) 
  314.       py = top_left.y + _y_offset;
  315.     else
  316.       py = top_left.y;
  317.     new_pt = new Point(px,py);
  318.     
  319.  
  320.     /* let the superclass do the rest */
  321.         super.damage_from_child(new_pt, larger_sz);
  322.       }
  323.  
  324.     //had:
  325.     //* @exception general PROPAGATED
  326.  
  327.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  328. }
  329. /*=========================== COPYRIGHT NOTICE ===========================
  330.  
  331. This file is part of the subArctic user interface toolkit.
  332.  
  333. Copyright (c) 1996 Scott Hudson and Ian Smith
  334. All rights reserved.
  335.  
  336. The subArctic system is freely available for most uses under the terms
  337. and conditions described in 
  338.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  339. and appearing in full in the lib/interactor.java source file.
  340.  
  341. The current release and additional information about this software can be 
  342. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  343.  
  344. ========================================================================*/
  345.